import { Component, OnInit, Input } from '@angular/core';
import { Lesson6ServiceService } from '../lesson6-service.service';

@Component({
  selector: 'app-lesson6-one',
  templateUrl: './lesson6-one.component.html',
  styleUrls: ['./lesson6-one.component.scss']
})
export class Lesson6OneComponent implements OnInit {

  @Input() type = 'left';

  checkAll = false;

  get data() {
    return this.type  === 'left' ? this.lesson6Servic.leftData : this.lesson6Servic.rightData;
  }

  constructor(public lesson6Servic: Lesson6ServiceService) {
    this.lesson6Servic.upData.subscribe(() => {
      this.setCheckAllStatus();
    });
  }

  ngOnInit() {
  }

  move() {
    this.type === 'left' ? this.lesson6Servic.LTR() : this.lesson6Servic.RTL();
  }

  checkAllFn() {

    this.data.forEach(element => {
      element.check = !this.checkAll;
    });
    this.checkAll = !this.checkAll;
  }

  setCheckAllStatus() {
    const arr = this.data.filter(v => v.check);
    this.checkAll = arr.length === this.data.length ? false : true;
  }
}
